using System;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace ConnectionForm{
    public partial class ConnectionForm : Form{
        public ConnectionForm(){
            InitializeComponent();
        }
        private void btn_conn_Click(object sender, EventArgs e){
            //编写数据库连接串
            string connStr = "Data source=CZBK-20190302ZQ\\MSSQLSERVER2012;
Initial Catalog=School; User ID=sa; Password=123456";
            try{
                using (SqlConnection conn = new SqlConnection(connStr)){
                    conn.Open(); //打开数据库连接
                    MessageBox.Show("数据库连接成功！");
                }
            }catch (Exception ex){
                MessageBox.Show("数据库连接失败！" + ex.Message);
            }
        }
    }
}